package com.wangnian.wangcai.service;

import com.wangnian.wangcai.dao.ChiGuDao;
import com.wangnian.wangcai.dao.DayInfoDao;
import com.wangnian.wangcai.dao.NameInfo;
import com.wangnian.wangcai.dao.NameInfoDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class AutoService {
    private static final Logger logger = LoggerFactory.getLogger(AutoService.class);

    private final ChiGuDao chiGuDao;
    private final NameInfoDao nameInfoDao;
    private final DayInfoDao dayInfoDao;

    public AutoService(ChiGuDao chiGuDao, NameInfoDao nameInfoDao, DayInfoDao dayInfoDao) {
        this.chiGuDao = chiGuDao;
        this.nameInfoDao = nameInfoDao;
        this.dayInfoDao = dayInfoDao;
    }

    /**
     * 自动买
     */
    @Transactional(rollbackFor = Exception.class)
    public void autoBuy() {
        //随机取一个
        List<NameInfo> nameInfos = nameInfoDao.getRandomChaoDi();
        for (NameInfo nameInfo : nameInfos) {
            //买入数量
//            int count = (int) (Config.get(buyMoney) / nameInfo.getPrice());
//            count = count / 100 * 100;
//            count = Math.max(count, 100);
//            boolean bool = mai(nameInfo.getName(), nameInfo.getCode(), nameInfo.getPrice(), "自动", count);
//            if (bool) {
//                nameInfo.setMai(true);
//                nameInfoDao.save(nameInfo);
//                return;
//            }
        }
    }


}
